home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1992 James H. Price, All rights reserved
- //
- // NUMINP.H
- //
- // Header for NumInputLine class
- //
-
- #if !defined( __NUMINP_H )
- #define __NUMINP_H
-
- #define Uses_TInputLine
- #include <tv.h>
-
- class TEvent;
-
- //
- // Mask characters:
- //
- // u digits ( 0,1,2 ... 9 ) only
- // d digits, initial minus sign
- // f digits, initial minus sign, decimal point
- //
- // The mask character is passed as an argument to NumInput line to
- // control what characters are accepted. IntInputLine has a default
- // argument of 'd'; DoubleInputLine has a default argument of 'f'.
- //
-
-
- template <class Type>
- class NumInputLine : public TInputLine {
-
- public:
-
- NumInputLine( const TRect& r, int maxLen, char aMaskChar );
-
- virtual void getData( void *rec );
- virtual void setData( void *rec );
- virtual void handleEvent( TEvent& event );
-
- private:
-
- char maskChar;
-
- virtual Boolean isValidChar( TEvent& event );
-
-
- // pure virtual functions -- must be overridden
- // in derived classes. See IntInputLine and DoubleInputLine
- // for examples of what these functions should do.
-
- virtual void numToStr( Type *rec, char *buf ) = 0;
- virtual Type strToNum( char *s ) = 0;
- virtual ushort dataSize() = 0;
-
- };
-
- class IntInputLine : public NumInputLine<int> {
-
- public:
-
- IntInputLine( const TRect& r, int maxLen, char maskChar='d' );
-
- private:
-
- void numToStr( int *rec, char *buf );
- int strToNum( char *s );
- ushort dataSize();
- };
-
- class DoubleInputLine : public NumInputLine<double> {
-
- public:
-
- DoubleInputLine( const TRect& r, int maxLen, char maskChar='f' );
-
- private:
-
- void numToStr( double *rec, char *buf );
- double strToNum( char *s );
- ushort dataSize();
- };
-
- #endif
-